<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Vue 2 交互效果实现</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.min.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        
        .container {
            display: flex;
            flex-direction: column;
            gap: 30px;
        }
        
        /* 悬停效果组件 */
        .hover-box {
            width: 200px;
            height: 100px;
            background-color: #f0f0f0;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 8px;
            transition: all 0.3s ease;
            position: relative;
        }
        
        .hover-box:hover {
            background-color: #e0e0e0;
            transform: translateY(-5px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }
        
        /* 点击动画组件 */
        .click-box {
            width: 200px;
            height: 100px;
            background-color: #4CAF50;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 8px;
            cursor: pointer;
            user-select: none;
            transition: all 0.2s ease;
        }
        
        .click-box:active {
            transform: scale(0.95);
        }
        
        .click-box.clicked {
            background-color: #2196F3;
            animation: pulse 0.5s;
        }
        
        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.1); }
            100% { transform: scale(1); }
        }
        
        /* 工具提示组件 */
        .tooltip-container {
            position: relative;
            display: inline-block;
        }
        
        .tooltip-trigger {
            width: 200px;
            height: 100px;
            background-color: #FF9800;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 8px;
            cursor: pointer;
        }
        
        .tooltip {
            position: absolute;
            background-color: #333;
            color: white;
            padding: 8px 12px;
            border-radius: 4px;
            font-size: 14px;
            z-index: 100;
            width: 200px;
            opacity: 0;
            transition: opacity 0.3s ease;
            pointer-events: none;
        }
        
        .tooltip.show {
            opacity: 1;
        }
        
        /* 工具提示位置 */
        .tooltip.top {
            bottom: calc(100% + 10px);
            left: 50%;
            transform: translateX(-50%);
        }
        
        .tooltip.bottom {
            top: calc(100% + 10px);
            left: 50%;
            transform: translateX(-50%);
        }
        
        .tooltip.left {
            right: calc(100% + 10px);
            top: 50%;
            transform: translateY(-50%);
        }
        
        .tooltip.right {
            left: calc(100% + 10px);
            top: 50%;
            transform: translateY(-50%);
        }
        
        /* 工具提示箭头 */
        .tooltip::after {
            content: "";
            position: absolute;
            border-width: 5px;
            border-style: solid;
        }
        
        .tooltip.top::after {
            top: 100%;
            left: 50%;
            margin-left: -5px;
            border-color: #333 transparent transparent transparent;
        }
        
        .tooltip.bottom::after {
            bottom: 100%;
            left: 50%;
            margin-left: -5px;
            border-color: transparent transparent #333 transparent;
        }
        
        .tooltip.left::after {
            left: 100%;
            top: 50%;
            margin-top: -5px;
            border-color: transparent transparent transparent #333;
        }
        
        .tooltip.right::after {
            right: 100%;
            top: 50%;
            margin-top: -5px;
            border-color: transparent #333 transparent transparent;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="container">
            <!-- 1. 鼠标悬停效果 -->
            <div>
                <h2>1. 鼠标悬停效果</h2>
                <div 
                    class="hover-box"
                    @mouseover="hoverActive = true"
                    @mouseleave="hoverActive = false"
                >
                    <p v-if="hoverActive">鼠标悬停中!</p>
                    <p v-else>悬停我试试</p>
                </div>
            </div>
            
            <!-- 2. 点击动画反馈 -->
            <div>
                <h2>2. 点击动画反馈</h2>
                <div 
                    class="click-box"
                    :class="{ clicked: isClicked }"
                    @click="handleClick"
                >
                    {{ isClicked ? '点击成功!' : '点击我试试' }}
                </div>
            </div>
            
            <!-- 3. 自定义工具提示 -->
            <div>
                <h2>3. 自定义工具提示</h2>
                <div class="tooltip-container">
                    <div 
                        class="tooltip-trigger"
                        @mouseenter="showTooltip = true"
                        @mouseleave="showTooltip = false"
                    >
                        悬停显示工具提示
                    </div>
                    <div 
                        class="tooltip top"
                        :class="{ show: showTooltip }"
                    >
                        这是一个自定义工具提示
                        <br>
                        可以显示多行内容
                    </div>
                </div>
                
                <div style="margin-top: 20px;">
                    <label>选择工具提示位置：</label>
                    <select v-model="tooltipPosition">
                        <option value="top">上方</option>
                        <option value="bottom">下方</option>
                        <option value="left">左侧</option>
                        <option value="right">右侧</option>
                    </select>
                </div>
                
                <div class="tooltip-container" style="margin-top: 30px;">
                    <div 
                        class="tooltip-trigger"
                        @mouseenter="showDynamicTooltip = true"
                        @mouseleave="showDynamicTooltip = false"
                    >
                        动态位置工具提示
                    </div>
                    <div 
                        class="tooltip"
                        :class="[tooltipPosition, { show: showDynamicTooltip }]"
                    >
                        当前位置: {{ tooltipPosition }}
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        new Vue({
            el: '#app',
            data: {
                hoverActive: false,
                isClicked: false,
                showTooltip: false,
                showDynamicTooltip: false,
                tooltipPosition: 'top'
            },
            methods: {
                handleClick() {
                    this.isClicked = true;
                    setTimeout(() => {
                        this.isClicked = false;
                    }, 1000);
                }
            }
        });
    </script>
</body>
</html>